import gradio as gr

from langchain.embeddings.openai import OpenAIEmbeddings
from langchain.chat_models import ChatOpenAI
from ai_translator import ai_translator

def translation(input_file, source_language, target_language):
    output_file_path = ai_translator.ai_translator(input_file, source_language, target_language)

    return output_file_path


def launch_gradio():
    demo = gr.Interface(
        fn=translation,
        title="PDF 翻译 Chatbot",
        inputs=[gr.File(label="上传PDF文件"),
                gr.Textbox(label="源语言(默认：英文)", placeholder="English", value="English"),
                gr.Textbox(label="目标语言(默认：中文)", placeholder="Chinese", value="Chinese")],
        outputs=[
            gr.File(label="下载翻译文件")
        ],
        allow_flagging="never",
    )

    demo.launch(share=True, server_name="0.0.0.0")

if __name__ == "__main__":
    # 启动 Gradio 服务
    launch_gradio()
